package test1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class KWICProcessor {
    public static String process(String content) {
        String[] words = content.split("\\s+");
        List<String> lines = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < words.length; j++) {
                if (j != i) {
                    sb.append(words[j]).append(" ");
                }
                sb.append(words[i]).append(" ");
            }
            // Remove trailing space
            lines.add(sb.toString().trim());
        }
        Collections.sort(lines);
        StringBuilder result = new StringBuilder();
        for (String line : lines) {
            result.append(line).append("\n");
        }
        return result.toString();
    }
}
